package dog

import (
	"os/exec"
	"fmt"
	"strings"
)

type LastWordCMD struct {
	cmd string
}

func (this *LastWordCMD) SetCmd(cmd string) {
	//exec.Command(cmd)
	this.cmd = cmd
}

func (this *LastWordCMD) Execute() {
	items := strings.Split(this.cmd, " ")
	var file string
	var args []string

	if len(items) == 0{
		fmt.Println("error not find cmd")
		return
	} else {
		file = items[0]
		args = items[1:]
	}

	d, err := exec.Command(file, args...).CombinedOutput()
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(string(d))
	}
}
